<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #ball{
            width: 100px;
            height: 100px;
            background-color: red;
            border-radius:50%;
            margin-left: 0px;
        }
        #ball2{
            width: 100px;
            height: 100px;
            background-color: red;
            border-radius:50%;
            margin-left: 0px;
        }
    </style>
</head>
<body>
<div id="ball"></div>
<div id="ball2"></div>
<input type="button" value="球1" onclick="move1('ball')">
<input type="button" value="球2" onclick="move2('ball2')">
<script>

    //找到小球原始的 marginLeft位置
    //1找元素的对象
    var ball = document.getElementById('ball');
    var ball2 = document.getElementById('ball');

    function go(){
        var t;//闭包
        function myMove(id){
            var htmlObj = document.getElementById(id);
            clearInterval(t);
            var end = 800;
            var offset = 2;     //速度
            function move(){
                var cssObj = getComputedStyle(htmlObj);
                var originL = parseInt(cssObj.marginLeft);
                if (originL>=end){
                    clearInterval(t);
                } else {
                    //2 根据找到的对象，再找这个对象的 css相关信息

                    //新的位置 = 原始位置+新的偏移量

                    htmlObj.style.marginLeft = originL + offset + 'px';
                }

            }
            t = setInterval(move,20);//1
        }
        return myMove;
    }

    var move1 = go();
    var move2 = go();









</script>

</body>
</html>